package com.huayi.datagovernance.utils;

import com.alibaba.fastjson.JSONObject;
import com.huayi.datagovernance.common.SysConstant;
import org.apache.commons.lang.StringUtils;

import java.util.*;

/**
 * 查询参数公共类
 */
public class ParamSet {

    //---------------------设备子类型---------------
    //modelid   classid  modelname   modelalias
//        10200000	102000	zwyc_yxgt	直线-运行杆塔
//        10200001	102000	zwyc_yxgt	耐张-运行杆塔
//        10300000	103000	zwyc_wlg	直线-物理杆塔
//        10300001	103000	zwyc_wlg	耐张-物理杆塔
//        310200000	3102000	dysb_dywlg	低压-直线物理杆塔
//        310200001	3102000	dysb_dywlg	低压-耐张物理杆塔
//        311400000	3114000	dysb_dyyxgt	低压-直线运行杆塔
//        311400001	3114000	dysb_dyyxgt	低压-耐张运行杆塔
//        10100000	101000	zwyc_dxd	导线段
//        10110000	101100	zwyc_dx	导线
//        310100000	3101000	dysb_dydxd	低压-导线段
//        310110000	3101100	dysb_dydx	低压-导线
//        10000000	100000	zwyc_xl	线路
//        11600000	116000	zwyc_xlblq	站外-线路避雷器
//        11700000	117000	zwyc_xlgzzsq	站外-线路故障指示器
//        310000000	3100000	dysb_dyxl	低压-线路
//        320100000	3201000	dysb_dydld	低压-电缆段
//        320200000	3202000	dysb_dydlzdt	低压-电缆终端头
//        320300000	3203000	dysb_dydlzjjt	低压-电缆中间接头
//        320400000	3204000	dysb_dydl	低压-电缆
//        320500000	3205000	dysb_dydlfzx	低压-电缆分支箱


    public static ArrayList<String> setOutpicParams(){
        ArrayList<String> tableNames = new ArrayList<String>();
        tableNames.add("T_TX_DYSB_DYYXGT");
        return tableNames;
    }



    //top设备限制类型
    //变压器/接入点/站房/杆塔
    public static ArrayList<String> setTopParams() {
        ArrayList<String> tableNames = new ArrayList<String>();
//        tableNames.add("t_tx_dysb_dywlg");
        tableNames.add("T_TX_DYSB_DYYXGT");
//        tableNames.add("T_TX_DYSB_DYYHJRD");
//        tableNames.add("t_tx_dysb_dydl");
//        tableNames.add("T_TX_DYSB_DYDLD");
//        tableNames.add("T_TX_DYSB_DYDXD");
//        tableNames.add("T_TX_DYSB_DYDX");
//        tableNames.add("T_TX_DYSB_DYZWLJX");
//        tableNames.add("T_TX_ZNYC_DZ");
        return tableNames;
    }
    //top设备限制类型
    //变压器/接入点/站房/杆塔
    public static String[] setTopStrParams =new String[]{"3114000"};


    //任务新建的设备列表展示（大类小类）
    //线路：杆塔、柱上变压器、导线、熔丝/站房：?/电缆：电缆终端头、电缆
    public static ArrayList<String> setTaskDevicesParamsByXL() {
        ArrayList<String> tableNames = new ArrayList<String>();
//        tableNames.add("t_tx_dysb_dywlg");//低压-直线物理杆塔	310200000	3102000
        tableNames.add("t_tx_dysb_dyyxgt");// 低压-直线运行杆塔	311400000	3114000
//        tableNames.add("t_tx_zwyc_zsbyq");//柱上-变压器 11000000	110000
//        tableNames.add("t_tx_dysb_dydxd");//310100000	3101000		低压-导线段
//        tableNames.add("t_tx_dysb_dydx");//310110000	3101100		低压-导线
//        tableNames.add("t_tx_dysb_dyrs");//311300000	3113000		低压-熔丝
//        tableNames.add("t_tx_dysb_dyrdq");//331000001	3310000		低压站内-熔丝
//        tableNames.add("t_tx_zwyc_zsdlsrdq");//11500000	115000		柱上-跌落式熔断器
//        tableNames.add("t_tx_dysb_dyzwcljx");//14000001	3430000		低压站外-超连接线
        return tableNames;
    }
    public static ArrayList<String> setTaskDevicesParamsByZF() {
        ArrayList<String> tableNames = new ArrayList<String>();
        return tableNames;
    }
    public static ArrayList<String> setTaskDevicesParamsByDL() {
        ArrayList<String> tableNames = new ArrayList<String>();
        tableNames.add("t_tx_dysb_dydld");//低压-电缆段	320100000	3201000
        tableNames.add("t_tx_dysb_dydlzdt");//低压-电缆终端头	320200000	3202000
        tableNames.add("t_tx_dysb_dydlzjjt");//低压-电缆中间接头	320300000	3203000
        tableNames.add("t_tx_dysb_dydl");//低压-电缆	320400000	3204000
        tableNames.add("t_tx_dysb_dydlfzx");//低压-电缆分支箱	320500000	3205000
        return tableNames;
    }

    /**
     * 物理杆类型显示
     * @return
     */
    public static ArrayList<Map<String,Object>> setSbzlxByWLG() {
        ArrayList<Map<String,Object>> list = new ArrayList<>();

        Map<String,Object> obj =new HashMap<>();
        obj.put("code",310200000);
        obj.put("codename","低压直线-物理杆塔");
        list.add(obj);

        Map<String,Object> obj1 =new HashMap<>();
        obj1.put("code",310200001);
        obj1.put("codename","低压耐张-物理杆塔");
        list.add(obj1);

        Map<String,Object> obj2 =new HashMap<>();
        obj2.put("code",311400000);
        obj2.put("codename","低压直线-运行杆塔");
        list.add(obj2);


        Map<String,Object> obj3 =new HashMap<>();
        obj3.put("code",311400001);
        obj3.put("codename","低压耐张-运行杆塔");
        list.add(obj3);

        Map<String,Object> obj4 =new HashMap<>();
        obj4.put("code",10300000);
        obj4.put("codename","中压直线-物理杆塔");
        list.add(obj4);

        Map<String,Object> obj5 =new HashMap<>();
        obj5.put("code",10300001);
        obj5.put("codename","中压耐张-物理杆塔");
        list.add(obj5);

        Map<String,Object> obj6 =new HashMap<>();
        obj6.put("code",10200000);
        obj6.put("codename","中压直线-运行杆塔");
        list.add(obj6);


        Map<String,Object> obj7 =new HashMap<>();
        obj7.put("code",321900000);
        obj7.put("codename","低压-墙支架");
        list.add(obj7);


        Map<String,Object> obj8 =new HashMap<>();
        obj8.put("code",10200001);
        obj8.put("codename","中压耐张-运行杆塔");
        list.add(obj7);

        return list;
    }

    public static List<Map<String,Object>> getfieldsLocal(){
        //设备名称、所属地市、运维单位、维护班组、所属线路、电压等级
        List<Map<String,Object>> resultData =new ArrayList<>();

        Map<String,Object> newField1 =new HashMap<>();
        newField1.put("fieldname","sbmc");
        newField1.put("fieldvalue","");
        newField1.put("fieldalias","设备名称");
        resultData.add(newField1);

        Map<String,Object> newField2 =new HashMap<>();
        newField2.put("fieldname","ssds");
        newField2.put("fieldvalue","");
        newField2.put("fieldalias","所属地市");
        resultData.add(newField2);

        Map<String,Object> newField3 =new HashMap<>();
        newField3.put("fieldname","ywdw");
        newField3.put("fieldvalue","");
        newField3.put("fieldalias","运维单位");
        resultData.add(newField3);

        Map<String,Object> newField4 =new HashMap<>();
        newField4.put("fieldname","whbz");
        newField4.put("fieldvalue","");
        newField4.put("fieldalias","维护班组");
        resultData.add(newField4);

//        Map<String,Object> newField5 =new HashMap<>();
//        newField5.put("fieldname","ssxl");
//        newField5.put("fieldvalue","");
//        newField5.put("fieldalias","所属线路");
//        resultData.add(newField5);

        Map<String,Object> newField6 =new HashMap<>();
        newField6.put("fieldname","dydj");
        newField6.put("fieldvalue","");
        newField6.put("fieldalias","电压等级");
        resultData.add(newField6);

        return resultData;
    }

    public static List<Map<String,Object>> getfieldsToSearchName(){
        //设备名称、所属地市、运维单位、维护班组、所属线路、电压等级
        List<Map<String,Object>> resultData =new ArrayList<>();

        Map<String,Object> newField1 =new HashMap<>();
        newField1.put("field","ssxl");
        newField1.put("fieldmc","ssxlmc");
        newField1.put("classid", SysConstant.DY_CLASSID_XL);
        newField1.put("fieldname","所属线路");
        resultData.add(newField1);

        Map<String,Object> newField2 =new HashMap<>();
        newField2.put("field","ssdx");
        newField2.put("fieldmc","ssdxmc");
        newField2.put("classid", SysConstant.DY_CLASSID_DX);
        newField2.put("fieldname","所属导线");
        resultData.add(newField2);

        Map<String,Object> newField3 =new HashMap<>();
        newField3.put("field","ssdxd");
        newField3.put("fieldmc","ssdxdmc");
        newField3.put("classid", SysConstant.DY_CLASSID_DXD);
        newField3.put("fieldname","所属导线段");
        resultData.add(newField3);

        Map<String,Object> newField4 =new HashMap<>();
        newField4.put("field","sswlg");
        newField4.put("fieldmc","sswlgmc");
        newField4.put("classid", SysConstant.DY_CLASSID_WLGT);
        newField4.put("fieldname","所属物理杆");
        resultData.add(newField4);

        Map<String,Object> newField5 =new HashMap<>();
        newField5.put("field","qsgt");
        newField5.put("fieldmc","qsgtmc");
        newField5.put("classid", SysConstant.DY_CLASSID_YXGT);
        newField5.put("fieldname","起始杆塔");
        resultData.add(newField5);

        Map<String,Object> newField6 =new HashMap<>();
        newField6.put("field","zzgt");
        newField6.put("fieldmc","zzgtmc");
        newField6.put("classid", SysConstant.DY_CLASSID_YXGT);
        newField6.put("fieldname","终止杆塔");
        resultData.add(newField6);

        Map<String,Object> newField7 =new HashMap<>();
        newField7.put("field","ssdl");
        newField7.put("fieldmc","ssdlmc");
        newField7.put("classid", SysConstant.DY_CLASSID_DL);
        newField7.put("fieldname","所属电缆");
        resultData.add(newField7);

        return resultData;
    }

    /**
     * 转换拼英成中文注解
     */
    public static List<Map<String,Object>> getchangeEnToCh(String key){
        List<Map<String,Object>> resultData =new ArrayList<>();

        Map<String,Object> newField1 =new HashMap<>();
        newField1.put("field","geotype");
        newField1.put("fieldalias","坐标类型");
        newField1.put("fieldvalue", SysConstant.SHAPE_TYPE.get(key));
        resultData.add(newField1);

        Map<String,Object> newField2 =new HashMap<>();
        newField2.put("field","yxdwmc");
        newField2.put("fieldalias","运行单位名称");
        resultData.add(newField2);

        Map<String,Object> newField3 =new HashMap<>();
        newField3.put("field","fieldalias");
        newField3.put("fieldalias","设备属性");
        resultData.add(newField3);

        Map<String,Object> newField4 =new HashMap<>();
        newField4.put("field","ywdwmc");
        newField4.put("fieldalias","运维单位名称");
        resultData.add(newField4);

        Map<String,Object> newField5 =new HashMap<>();
        newField5.put("field","modelalias");
        newField5.put("fieldalias","设备类型名称");
        resultData.add(newField5);

        Map<String,Object> newField6 =new HashMap<>();
        newField6.put("field","ssdx");
        newField6.put("fieldalias","所属导线");
        resultData.add(newField6);

        Map<String,Object> newField7 =new HashMap<>();
        newField7.put("field","sswlgzlx");
        newField7.put("fieldalias","所属物理杆子类型");
        newField7.put("optional", ParamSet.setSbzlxByWLG());//字段包含所属物理杆子类型（特殊处理）
        resultData.add(newField7);

        return resultData;
    }

    /**
     * 本地必须要的动态表单字段
     *     t.fieldname,t.fieldalias,t.nullable AS isrequired,m.codeexpress
     * @return
     */
    public static List<JSONObject> getfieldsLocalMustbe(){
        List<JSONObject> resultData =new ArrayList<>();

        JSONObject newField1 =new JSONObject();
        newField1.put("fieldname","points");
        newField1.put("fieldalias","坐标(json格式)");
        resultData.add(newField1);

        JSONObject newField2 =new JSONObject();
        newField2.put("fieldname","shape");
        newField2.put("fieldalias","坐标(数据库格式)");
        resultData.add(newField2);

        JSONObject newField3 =new JSONObject();
        newField3.put("fieldname","geotype");
        newField3.put("fieldalias","坐标格式");
        resultData.add(newField3);

        return resultData;
    }

    /**
     * 图形台账表的字段(重复字段不同值) ssxlsbid -ssxl
     */
    public static JSONObject validTZField(JSONObject device){
        JSONObject device1=new JSONObject();
        for(String key :device.keySet()){
            device1.put(key,device.get(key));
        }
        String[] fields =new String[]{"ssxlsbid","ssdxsbid","sswlgsbid","ssgtsbid","qsgtsbid","zzgtsbid","ssdxdsbid","glwlgsbid"};
        String[] fields1 =new String[]{"tzssxl","tzssdx","tzsswlg","tzssgt","tzqsgt","tzzzgt","tzssdxd","tzglwlg"};

        for(String key :device.keySet()){
            if(device.getInteger("addflag")== SysConstant.operate_edit){
                for(String key1: Arrays.asList(fields)){
                    if(StringUtils.equals(key1,key)){ //ssxlsbid==ssxlsbid
                        String field =key1.substring(0,key1.length()-4);//ssxl
                        device1.put(field+"oid",device.get(field));//ssxloid = device.get("ssxl")
                        device1.put(field,device.get(key));//ssxl=device.get("ssxlsbid")
                        break;
                    }
                }
            }
            else {
                for(String key1: Arrays.asList(fields1)){
                    if(StringUtils.equals(key1,key)){
                        String field =key1.substring(2,key1.length());
                        device1.put(field+"oid",device.get(field));
                        device1.put(field,device.get(key));
                        break;
                    }
                }
            }
        }
        return device1;
    }

    public static final String [] dataBrokerNoField =new String[]{"shape","toponodeid","disoid","datatype","geotype","type","points","sboid"};//数据代理排除的字段

    //需要获取Name的字段，并且需要下拉查询
    public static final String[] fieldsToSearchName = new String[]{
            "ssxl",
            "ssdx",
            "ssdxd",
            "sswlg",
            "qsgt",
            "zzgt",
            "ssdz",
            "qsdz",
            "ssdl",
            "ssdld",
            "ssbyq",
            "ssjg",
            "qdsb",
            "zdsb",
            "ssgt"};
    public static final Map<String,String> field2Classids =new HashMap();
    static {
        field2Classids.put(fieldsToSearchName[0], SysConstant.DY_CLASSID_XL+","+ SysConstant.CLASSID_XL);
        field2Classids.put(fieldsToSearchName[1], SysConstant.DY_CLASSID_DX+","+ SysConstant.CLASSID_DX);
        field2Classids.put(fieldsToSearchName[2], SysConstant.DY_CLASSID_DXD+","+ SysConstant.CLASSID_DXD);
        field2Classids.put(fieldsToSearchName[3], SysConstant.DY_CLASSID_WLGT+","+ SysConstant.CLASSID_WLGT);
        field2Classids.put(fieldsToSearchName[4], SysConstant.DY_CLASSID_YXGT+","+ SysConstant.CLASSID_YXGT);
        field2Classids.put(fieldsToSearchName[5], SysConstant.DY_CLASSID_YXGT+","+ SysConstant.CLASSID_YXGT);
        field2Classids.put(fieldsToSearchName[6], SysConstant.CLASSID_DZ+"");
        field2Classids.put(fieldsToSearchName[7], SysConstant.CLASSID_DZ+"");
        field2Classids.put(fieldsToSearchName[8], SysConstant.DY_CLASSID_DL+","+ SysConstant.CLASSID_DL);
        field2Classids.put(fieldsToSearchName[9], SysConstant.DY_CLASSID_DLD+","+ SysConstant.CLASSID_DLD);
        field2Classids.put(fieldsToSearchName[10], SysConstant.CLASSID_ZSBYQ+","+ SysConstant.CLASSID_PDBYQ);
        field2Classids.put(fieldsToSearchName[11], SysConstant.CLASSID_JGDY+"");
        field2Classids.put(fieldsToSearchName[12], SysConstant.DY_CLASSID_DLZD+","+ SysConstant.CLASSID_DLZD);
        field2Classids.put(fieldsToSearchName[13], SysConstant.DY_CLASSID_DLZD+","+ SysConstant.CLASSID_DLZD);
        field2Classids.put(fieldsToSearchName[14], SysConstant.DY_CLASSID_YXGT+","+ SysConstant.CLASSID_YXGT);
    }

    //数据库字段特殊
    public static final String DB_FIELD_CKZT ="ckzt";//常开状态ckzt写死 常闭：2097151
    public static final String DB_FIELD_CKZT_VALUE ="2097151";


    /**
     * 动态表单显示字段自定义
     */
    public static final String[] MODELID_BYQ_ALL = new String[]{"30200003","30200001","30200000","30100003","30100004","11000001","11000000","30200002","30100002","30100001","30100005","11000002","30200004","23000000","39200000"};//所有变压器sbzlx
    public static final String[] MODELID_GT_ALL = new String[]{"10300001","311400000","10300000","310200000","10200000","311400001","10200001","310200001","110500001"};//所有杆塔sbzlx
    public static final String[] MODELID_ZF_ALL = new String[]{"32500000","20400000","32400000","30000000","30000003","30000005","30000001","30000006","30000004","32300000","32600000","30000099","34300000"};//所有站房sbzlx
    public static final String[] MODELID_DL_ALL = new String[]{"20100000","320100000","28200000"};//所有电缆段sbzlx

    public static final String[] MODELID_ZNSB_ALL = new String[]{"321500001","30700000","30600000","30900000","30500000","30300000","31500000","33000000","331200000","331100000","330900000","331000000","31200000","39000007","39000008","39000002","39000005","30600008","31200001","30600007","30600004","30600006","30600002","31100000","321700000","36100000","32100000","30400000","39000003","39000004","39000001","36000001","31800000","30800000","31800001","36000000","30600001","31400000","31700000","32200000","31900000","30600005","30700001","30600003","31400001","321500000","321500002","31600000","30700002","331300000","321500005","38000001","38000000","34000000","31000000","39000006","33300000","35000001","35000000","32000000","32000001","31300001","30900001","39000009","34500000","33900000","321500098","39000098","30700098","30500099","399000001","399000002","399000003","30900002","331400000","331000001","32300001","35100000","39200000","510210000","39500000"};//所有站内设备sbzlx

    public static final Map<String,String[]> getCustomFieldsBysbzlx =new HashMap();
    static {
        //变压器名称	容量	变压器型号（可以查看）	所属线路	所属杆塔	变压器信息（营销那个id）	变压器性质
        getCustomFieldsBysbzlx.put("BYQ",new String[]{"sbmc","edrl","xh","ssxl","ssgt","syxz"});
        //杆塔名称	所属线路	电压等级	设备子类型
        //系统类型、杆塔材质 设备名称
//        getCustomFieldsBysbzlx.put("GT",new String[]{"sbmc","ssxl","dydj","sbzlx"});
        getCustomFieldsBysbzlx.put("GT",new String[]{"apptype","gtcz","sbmc","ssxl"});
        // 站房名称
        getCustomFieldsBysbzlx.put("ZF",new String[]{"sbmc"});
        //起点终端头名称	终点终端头名称	所属线路
        getCustomFieldsBysbzlx.put("DL",new String[]{"qdsb","zdsb","ssxl"});
        //站内设备名称	型号
        getCustomFieldsBysbzlx.put("ZNSB",new String[]{"sbmc","xh"});
    }



}
